#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@file_name: multithreading_status_code_reading.py
@date: 2025-07-21 17:31
@author: Falling Snow
@desc: 多线程状态码的数据读取
"""

import threading
import time

import requests


def read_example() -> None:
    response = requests.get("https://www.example.com")
    print(response.status_code)


if __name__ == '__main__':
    sync_start = time.time()
    thread_1 = threading.Thread(target=read_example)
    thread_2 = threading.Thread(target=read_example)
    thread_3 = threading.Thread(target=read_example)
    thread_4 = threading.Thread(target=read_example)

    thread_1.start()
    thread_2.start()
    thread_3.start()
    thread_4.start()

    print("所有线程已经启动")
    thread_1.join()
    thread_2.join()
    thread_3.join()
    thread_4.join()

    sync_end = time.time()

    print(f"多线程运行耗费{(sync_end - sync_start):.4f} 秒!")
